package com.lanyun.controller;

import com.lanyun.common.R;
import com.lanyun.entity.RoutesEntity;
import com.lanyun.mapper.RoutesMapper;
import com.lanyun.wrapper.RoutesQuery;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: TODO
 * @author: LanYun
 * @date: 2022/5/2 20:05
 * @Version: 1.0
 */
@Api()
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/routes")
public class RoutesController {
    @Autowired
    @Qualifier("routesMapper")
    private RoutesMapper routesMapper;

    @GetMapping
    public R getRoutes(){
        List<RoutesEntity> routesEntities = routesMapper.listEntity(new RoutesQuery());
        return R.ok().data("sclist",routesEntities);
    }

    @PutMapping("/save")
    public R save(@RequestBody RoutesEntity entity){
        routesMapper.saveOrUpdate(entity);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id")Long id){
        routesMapper.deleteById(id);
        return R.ok();
    }
}
